package BL;
import java.sql.*;

public class AccessDB {

	public AccessDB() {
	}
	
	public static String getSelectAllString() throws SQLException, ClassNotFoundException {
		// spezifische Datenbanktreiber laden
		Class.forName("org.hsqldb.jdbcDriver"); 
				
		// Verbindung zur Datenbank "test" aufbauen
		Connection con = DriverManager.getConnection( "jdbc:hsqldb:file:/Users/julianruess/Documents/201301_Java_Projekt/HSQLDB_AroundMe;shutdown=true", "sa", "");

		// SQL-Anweisungs-Objekt erzeugen
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery("SELECT * FROM Standorte");
		String all = new String("");
				
		// Resultat der SQL-Anweisung verarbeiten
		for (int i=1; rs.next() ; i++){
			all = all + rs.getString(i);
		}
		
		rs.close(); st.close(); con.close();
		   
		return all;
	}
	
	public void showDB() throws SQLException, ClassNotFoundException {
		// spezifische Datenbanktreiber laden
		Class.forName("org.hsqldb.jdbcDriver"); 
		
		// Verbindung zur Datenbank "test" aufbauen
		Connection con = DriverManager.getConnection( "jdbc:hsqldb:file:/Users/julianruess/Documents/201301_Java_Projekt/HSQLDB_AroundMe;shutdown=true", "sa", "");

		// SQL-Anweisungs-Objekt erzeugen
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery("SELECT * FROM Standorte");
		
		// Resultat der SQL-Anweisung verarbeiten
		while (rs.next()) {
			System.out.print(rs.getString(1) + " "); 
			System.out.print(rs.getString(2) + " "); 
			System.out.print(rs.getString(3) + " "); 
			System.out.println(rs.getString(4));
		
		}
		
		rs.close(); st.close(); con.close();
	}
	
}
